package com.haoran.dwz.common.redis;

import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;

import com.haoran.dwz.common.handler.PermissionCacheHandler;


public class PermissionMessageSender implements PermissionCacheHandler {

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	private RedisTemplate<String, Serializable> redisTemplate;


	public PermissionMessageSender(RedisTemplate<String, Serializable> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	private void publish(String channel, String message) {
		redisTemplate.convertAndSend(channel, message);
	}

	public RedisTemplate<String, Serializable> getRedisTemplate() {
		return redisTemplate;
	}

	public void setRedisTemplate(RedisTemplate<String, Serializable> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	@Override
	public boolean synchronizePermissionCache() {
		try {
			publish(TOPIC_OF_PERMISSION, SYNCHRONIZE_PERMISSION_CACHE_MESSAGE);
		} catch (Exception e) {
			logger.error("发布同步系统权限缓存消息失败", e);
			e.printStackTrace();
		}
		return false;
	}
 
}